<template>
	<view style="padding: 20px;box-sizing: border-box;">
		<view style="padding: 20px;">
			<image :src="img" mode="widthFix" style="width: 100%;"></image>
		</view>
		<view class="flex">
			<view class="w50">
				<image @click="sele(0)" :class="num==0?'imgactive':''" :src="form.cover_image" mode="widthFix"  style="width: 100%;"></image>
			</view>
			<view class="w50">
				<image @click="sele(1)"  :class="num==1?'imgactive':''" :src="form.second_image" mode="widthFix"  style="width: 100%;"></image>
			</view>
		</view>
		<button @click="shebeijing" class="button cfff">
			设为空间头像
		</button>
		<button style="margin-top: 20px;" open-type="share" class="button cfff">
			邀请Ta一起换头像
		</button>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				form:{},
				img:'',
				num:0
			}
		},
		onShareAppMessage(res) {
		   if (res.from === 'button') {// 来自页面内分享按钮
		     console.log(res.target)
		   }
		   return {
		     title: '快来和我一起换头像吧',
			 path:'/pages/content/content'
		   }
		 },
		onLoad(e) {
			this.form=JSON.parse(e.item)
			this.img=this.form.cover_image
		},
		methods: {
			sele(e){
				this.num=e
				if(e==0){
					this.img=this.form.cover_image
				}else{
					this.img=this.form.second_image
				}
			},
			async shebeijing(e){
				let data = {
					my_space_id:this.vuex_user_content.id,
					space_media_id:this.form.id,
					media_type:1,
					field:''
				}
				if(this.num==0){
					data.field='cover_image'
				}else{
					data.field='second_image'
				}
				let res = await this.$u.api.change_media(data)
				uni.showToast({
					title:'设置成功',
					icon:'none'
				})
				console.log(res)
			},
		}
	}
</script>

<style>
page{
	background: #fff;
}
.imgactive{border: #fa1e8a dashed 1px;}
</style>
